# GDIR define
GDIR=../../..

# MACIPATH define
MACIPATH=$(GDIR)/MaCI


# External includes
include $(GDIR)/GIMI/Makefile.gimi
include $(MACIPATH)/interfaces/MaCI-interfaces.Makefile


# params
CC=gcc
CXX=g++
EXTRADEFS=-DLINUX_OS
MACIPATH=$(GDIR)/MaCI
UTILSPATH=$(GDIR)/utils
BUSPATH=$(MACIPATH)/bus
DRIVERPATH=$(MACIPATH)/drivers
MACIINTERFACEPATH=$(MACIPATH)/interfaces
INCLUDES=-I$(UTILSPATH) $(INCGIMI) \
	$(MACI_INCLUDE_PATHS)
CFLAGS=-O0 -g3 -Wall $(INCLUDES) $(CE) \
	$(EXTRADEFS)
CPPFLAGS=-O0 -g3 -Wall $(INCLUDES) -Weffc++ $(EXTRADEFS)
LD=g++
LDFLAGS=-ljpeg
LIBS=-lrt -lpthread $(LIBSGIMI)


# Sources 'base' (required external links)
SRCSC=$(CGIMI) 
SRCSCPP=$(CPPGIMI) $(MACI_EXT_SRC_CPP) $(MACI_BASE_SRC_CPP)
VPATH=

# Construct final lists of CPP and C objects
OBJSC=$(SRCSC:.c=.o)
OBJSCPP=$(SRCSCPP:.cpp=.opp)

# Define COMPILE and LINK commands
COMPILEC=$(CC) $(CFLAGS) -c
COMPILECPP=$(CXX) $(CPPFLAGS) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean real-clean


all: UnitClient UnitServer UnitData_standalone

UnitServer: UnitData.opp UnitServer.opp
	@echo "UnitServer components - Compiled OK."

UnitClient: UnitData.opp UnitClient.opp
	@echo "UnitClient components - Compiled OK."


UnitData_standalone: $(OBJSC) $(OBJSCPP) UnitData.cpp
	@rm -f UnitData.opp
	@$(COMPILECPP) -D COMPILE_UNITDATA_STANDALONE_MAIN \
	UnitData.cpp -o UnitData.opp
	@echo "      [CXX-STANDALONE] UnitData.cpp"
	@$(LINK) -o $@ $(OBJSC) $(OBJSCPP) \
	UnitData.opp

clean:
	@rm -f *.o *.opp *~ UnitData_standalone
	@echo "      [CLEAN]"

real-clean realclean: clean
	@rm -f $(OBJSC) $(OBJSCPP)
	@echo "      [REAL-CLEAN]"

# Compile rule for all .o (.c) file
%.o:	%.c
	@$(COMPILEC) -o $@ $<
	@echo "      [CC] $<"

# Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
	@$(COMPILECPP) -o $@ $<
	@echo "      [CXX] $<"


